/**
 * 
 */
package com.suyx.job.job;

import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.alibaba.fastjson.JSON;
import com.suyx.job.entity.JobInfo;
import com.suyx.job.entity.Result;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Administrator
 *
 */
@Slf4j
public class ReadQydAppJob extends ExecuteJob {

	@Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("进入了--- ReadQydAppJob: ");
        JobDataMap param = jobExecutionContext.getMergedJobDataMap();
        jobInfo = (JobInfo) param.get("jobInfo");
        String subject = "项目：" + jobInfo.getJobGroup() + ",执行任务：" + jobInfo.getJobName();
        log.info("id:" + jobInfo.getJobId() + "," + subject);
        
        Result result = executeCall();
        log.info("ReadQydAppJob执行完成~");
    }
	
	@Override
    public Result executeCall() {
		String[] deviceCodes = {"08ed0cbd7d2a","0d5e784c7d32"};
		for(String deviceCode:deviceCodes){
			new Thread() {
	            @Override
	            public void run() {
	            	try {
	                    Result result = restTemplate.getForObject(jobInfo.getExecuteAddress() + "/" + deviceCode, Result.class);
	                    if (result != null && result.isSuccess()) {
	                        log.info("执行成功： "+ this.getName() + JSON.toJSONString(result));
	                        //return new Result(true,"200","执行成功！！");
	                    } else {
	                        log.error("执行失败："+ this.getName() + JSON.toJSONString(result));
	                        //return new Result(false,"500","执行失败，请尽快处理！！！");
	                    }
	                } catch (Exception e) {
	                    log.error( "执行时出现异常："+ this.getName() + e.getMessage());
	                    //return new Result(false, "500", "执行时出现异常");
	                }
	            }
			}.start();
		}
		return new Result();
    }

}
